var lengthOfLongestSubstring = function(s) {
  let str = ''
  let arr = []
  let len = 0
  for(let i = 0; i < s.length; i++) {
    let index = str.indexOf(s[i])
    if(index !== -1) {
      str = str.substr(index + 1)
      arr.splice(0, index + 1)
    }
    str += s[i]
    arr.push(s[i])
    console.log(str, index, arr)
    len = Math.max(len, str.length)
  }
  return len
};
console.log(lengthOfLongestSubstring("aaba!wa"))